﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Configuration;
using System.Text.RegularExpressions;
using System.Globalization;

namespace Slja.SMS.BLL

{
    internal class SmsUti
    {
        internal static List<Slja.SMS.Model.sms_MsgRecive> AssignReciveModelList(List<SmsMsgInfo> msgList)
        {
            // List<SmsMsgInfo> msgList = ConvertRecivedMsgFormat(arrUnRead);

            List<Slja.SMS.Model.sms_MsgRecive> listModel = new List<Slja.SMS.Model.sms_MsgRecive>();
            //写入数据库
            Slja.SMS.Model.sms_MsgRecive model = null;
            for (int i = 0; i < msgList.Count; i++)
            {
                model = new Slja.SMS.Model.sms_MsgRecive();
                model.Code = msgList[i].Code;
                model.MsgContent = msgList[i].MsgBody;
                model.MsgIndex = msgList[i].Index;
                model.ReadMemo = "";
                model.RecvTime = msgList[i].ReciveTime;
                model.SendNO = msgList[i].SendNO;
                model.Status = 0;//未读(放入数据库，尚未读)
                listModel.Add(model);
            }
            return listModel;
        }
        internal static List<SmsMsgInfo> ConvertRecivedMsgFormat(string[] arrMsgStr)
        {
            List<SmsMsgInfo> list = new List<SmsMsgInfo>();
            string[] arrInfo;
            for (int i = 0; i < arrMsgStr.Length; i++)
            {
                if (!string.IsNullOrEmpty(arrMsgStr[i]))
                {
                    char Separator = (char)1;
                    arrInfo = arrMsgStr[i].Split(Separator);//信息字符串（[MMNN,中心号码，手机号码，发送时间，短信内容,短信序号] MM这批短信总条数 NN本条所在序号）
                    SmsMsgInfo info = new SmsMsgInfo();
                    info.Code = "";
                    info.Index = int.Parse(arrInfo[5]);
                    info.MsgBody = arrInfo[4];
                    info.ReciveTime = DateTime.ParseExact(arrInfo[3], "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
                    info.SendNO = arrInfo[2];
                    list.Add(info);
                }
            }
            return list;
        }
    }
    /// <summary>
    /// 短信读取状态
    /// </summary>
    public enum SmsMsgType
    {
        WaitingRead=0,
        HasRead=1,
        WaitingSend=2,
        HasSent=3,
        All=4
        //0：未读短信；1：已读短信；2：待发短信；3：已发短信；4：全部短信
    }
    public struct SmsMsgInfo
    {
        public int Index;
        public string Code;
        public string SendNO;
        public string MsgBody;
        public DateTime ReciveTime;

    }
}